<template>
  <a-modal
    :title="formInfo.id==undefined?'新增':'修改'"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :destroyOnClose="true"
    @ok="handleSubmit"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model
        ref="ruleForm"
        :model="formInfo"
        :label-col="$global.labelCol"
        :wrapper-col="$global.wrapperCol"
      >
            <a-row>
              <a-col :span="12">
            <a-form-model-item label="院区编码" prop="areaCode" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.areaCode" placeholder="请输入院区编码"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="院区名称" prop="areaName" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.areaName" placeholder="请输入院区名称"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
                <a-form-model-item label="联系电话" prop="tel" :rules="$valid.required" :maxLength="50">
                  <a-input v-model="formInfo.tel" placeholder="请输入联系电话"/>
                </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="院区地址" prop="areaAddress" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.areaAddress" placeholder="请输入院区地址"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
            <a-col :span="24">
                <a-form-model-item  :labelCol="$global.labelTextAreaCol"  :wrapperCol="$global.wrapperTextAreaCol"  label="院区简介">
                    <a-input v-model="formInfo.areaRemark" type="textarea"/>
                </a-form-model-item>
            </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
  import { getAction, postAction } from '@/api/manage'
  export default {
    name: 'HealthAreaEdit',
    components: {
    },
    data () {
      return {
        visible: false,
        confirmLoading: false,
        formInfo: {
          areaCode: undefined,
          areaName: undefined,
          areaRemark: undefined,
          areaUrl: undefined,
          areaAddress: undefined,
          tel: undefined,
          sort: undefined,
          createTime: undefined,
          wx: ''
        },
        url: {
          saveInfo: '/system/healthArea/save',
          getInfo: '/system/healthArea/info'
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit()
      },
      edit (record) {
        this.$objToOverride(this.formInfo, record)
        if (this.formInfo.id) {
          getAction(this.url.getInfo, { 'id': record.id }).then(res => {
            this.$nextTick(() => {
              this.formInfo = res.result.data
            })
          })
        }
        this.visible = true
      },
      // 确定
      handleSubmit () {
        // 触发表单验证
        this.confirmLoading = true
        this.$refs.ruleForm.validate(valid => {
          console.log(valid)
          if (valid) {
            postAction(this.url.saveInfo, this.formInfo).then(res => {
              this.$message.success(res.content)
              this.$emit('ok', this.formInfo)
              this.close()
            }).finally(() => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      // 关闭
      handleCancel () {
        this.close()
      },
      close () {
        this.$refs.ruleForm.resetFields()
        this.$objToReset(this.formInfo)
        this.$emit('close')
        this.visible = false
      },
      editorOk (val) {
        this.formInfo.content = val
      }
    }
  }
</script>
